<?php 
## include required files
/*******************************/
require_once '../model/users.php';
require_once '../model/moduleuser.php';
## Paginaton class
require_once ("../includes/classes/pagination_class.php");
/*******************************/
## Create Objects
/*******************************/
$userObj = new Model_Users();
$moduleObj=new Model_ModuleUser();
/*******************************/




if(isset($_GET['action']) == 'delete' && isset($_GET['id']) != ''&& isset($_GET['photoid']) != '') {
	$PhotoID = base64_decode($_GET['photoid']);
	$userPhotoDetArray = $userObj->getUserPhotoDetailsByPhotoId($PhotoID);	

	
	@unlink('../uploads/tradesmanjobs/'.$userPhotoDetArray['image']);
	
	$userObj->deleteWorkPhotoById($PhotoID);
	$_SESSION['msg'] = "<div class='success_msg'style='margin-top:5px;margin-bottom: 20px;'><span>Work photo deleted successfully !</span></div>";

	header('location:'.SITE_URL.'/admin/home.php?q=tradesmanuserworkphoto&id='.$_GET['id'].'&page='.$_GET['page']);
	exit;
}


## Fetch user details by id
if($_GET['id'] != '') {
	$user_id = base64_decode($_GET['id']);	
	$user_details = $userObj->getUserDetailsByUserId($user_id);
	$smarty->assign('user_details', $user_details);
}



## Get search parameters in variables - 
if(isset($_POST['search']) != '' && $_POST['search'] != 'Title') {
//	echo 'aaaaaa';exit;
	$searchindex = addslashes($_POST['search']);
} else if($_GET['search'] != '') {
	$searchindex = addslashes($_GET['search']);
} else {
	$searchindex = '';
}
// Assign search variable to show in search textbox
$smarty->assign('search', stripslashes (stripslashes ($searchindex)));

##  --------- Pagination part first start --------------##
	if( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] != "" ) {
		$pageNum = $_GET[ 'page' ];
	} else {
		$pageNum = 1;
	} 
	$rowsPerPage = ROW_PER_PAGE;

		$pageName = "home.php?q=tradesmanuserworkphoto&id=".$_GET['id'].""; 

	## Count all the records
	$userArray = $userObj->getAllWorkPhotoByUserID($user_id,$searchindex);
	$total_rows = count($userArray);
	$offset	= ($pageNum - 1) * $rowsPerPage;
	$smarty->assign('page', $pageNum);
##  --------- Pagination part first end --------------##


##  --------- Pagination part second start --------------##
	$newid = $pageNum * $rowsPerPage - $rowsPerPage + 1;
	$smarty->assign('newid', $newid);
	$userArray = $userObj->getAllWorkPhotoByUserID($user_id,$searchindex,$rowsPerPage,$offset);
	//echo "<pre>"; print_r($userArray);exit;
	
	
	$smarty->assign('userArray', $userArray);
	
	if($searchindex != '') {
		$other_id = "search=".$searchindex;
	} else {
		$other_id = '';
	}
	
	if($total_rows > ROW_PER_PAGE) {
		$pg = new pagination();					// CREATING OBJECT OF THE PAGINATION CLASS
		$pgnation = $pg->pagination_admin( $total_rows , $rowsPerPage , $pageNum , $pageName , $other_id, $class);	
		$smarty-> assign("pagination",$pgnation);
	}
##  --------- Pagination part second end --------------##	

## Assign session message to smarty variable and unset session variable
if($_SESSION['msg'] != '') {
	$smarty->assign('msg', $_SESSION['msg']);	
	unset($_SESSION['msg']);
}

## Set active class variable for left menu  (main menu and sub menu)
$smarty->assign('activeclass', 'tradesmanuser');
$smarty->assign('mainmenu', '4');

## Unset all the objects created which are on this page
unset($userObj);
unset($moduleObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'tradesmanuser/tradesmanuserworkphoto.tpl');
unset($smarty);
?>